package com.heatingcharge.controller.customer;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.heatingcharge.common.util.R;
import com.heatingcharge.dto.CustomerDTO;
import com.heatingcharge.entity.base.HeatYear;
import com.heatingcharge.entity.customer.Customer;
import com.heatingcharge.param.CustomerParam;
import com.heatingcharge.service.customer.ICustomerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 客户资料  前端控制器
 * </p>
 *
 * @author devin.jiang
 * @since 2019-07-12
 */
@RestController
@RequestMapping("/customer")
public class CustomerController {
    @Autowired
    ICustomerService customerService;

    /**
     * 分页获取用户信息
     * @param page
     * @param customerDTO
     * @return
     */
    @GetMapping
    public R getCustomers(Page page,CustomerDTO customerDTO){
        IPage<CustomerDTO> customer = customerService.getCustomer(page, customerDTO);
        return R.ok(customer);
    }

    @PostMapping
    public R save(@RequestBody CustomerParam customerParam){
        if (customerService.save(customerParam)>0){
            return R.ok();
        }
        return R.error();
    }

    @PutMapping
    public R update(@RequestBody CustomerParam customerParam){
        if (customerService.update(customerParam)>0){
            return R.ok();
        }
        return R.error();
    }

    @DeleteMapping("/{id}")
    public R delete(@PathVariable("id") Integer id){
        if (customerService.removeById(id)){
            return R.ok();
        }
        return R.error();
    }
}

